<%#
 Copyright 2020 Developer X <dev@x-wrt.com>
 Licensed to the public under the Apache License 2.0.
-%>

<%+header%>

<script type="text/javascript">//<![CDATA[
	var stxhr = new XHR();

	function update_status(field, proto)
	{
		var addr = field.value;

		var legend = document.getElementById('sdwan-rc-legend');
		var output = document.getElementById('sdwan-rc-output');

		if (legend && output)
		{
			output.innerHTML =
				'<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
				'<%:Waiting for command to complete...%>'
			;

			legend.parentNode.style.display = 'block';
			legend.style.display = 'inline';

			stxhr.post('<%=url('admin/natcap_sdwan/activation_sn')%>/' + addr, { token: '<%=token%>' },
				function(x)
				{
					if (x.responseText)
					{
						legend.style.display = 'none';
						output.innerHTML = String.format('<pre>%h</pre>', x.responseText);
					}
					else
					{
						legend.style.display = 'none';
						output.innerHTML = '<span class="error"><%:Bad address specified!%></span>';
					}
				}
			);
		}
	}
//]]></script>

<form method="post" action="<%=url('admin/natcap_sdwan/activation')%>">
	<div class="cbi-map">
		<h2 name="content"><%:TOP UP%></h2>

		<div class="cbi-section">
			<legend><%:Enter top-up code%></legend>

			<div class="table">
				<div class="tr">
					<div class="td left">
						<input style="margin: 5px 0" type="text" value="" name="sdwan_code" /><br />
						<input type="button" value="<%:Active%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.sdwan_code)" />
					</div>
				</div>
			</div>
		</div>
	</div>

	<div class="cbi-section" style="display:none">
		<strong id="sdwan-rc-legend"></strong>
		<span id="sdwan-rc-output"></span>
	</div>
</form>

<%+footer%>
